package org.fing.edu.uy.esbadp.core.compare.wsdl;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import org.fing.edu.uy.esbadp.logger.LoggerADP;

public class OperationDiff implements Serializable {
	
    private static final java.util.logging.Logger logger = LoggerADP.getLogger(OperationDiff.class.getSimpleName());
    
    private static final long serialVersionUID = 1L;

    public static enum Modification { NEW, RENAME, DELETE, ONLY_PARAMETER };
    private String name;
    private String newName;
    private Modification modificationTypeName;
    private List<ParameterDiff> parameterChanges;
    
    public OperationDiff(){
        
    }

    public OperationDiff(String name, Modification modificationTypeName) {
        this.name = name;
        this.modificationTypeName = modificationTypeName;
    }
    
    public OperationDiff(String name, String newName, Modification modificationTypeName) {
        this.name = name;
        this.newName = newName;
        this.modificationTypeName = modificationTypeName;
    }
    
    public OperationDiff(String name, List<ParameterDiff> parameterChanges, Modification modificationTypeName) {
        this.name = name;
        this.parameterChanges = parameterChanges;
        this.modificationTypeName = modificationTypeName;
    }

    public Modification getModificationTypeName() {
        return modificationTypeName;
    }

    public void setModificationTypeName(Modification modificationTypeName) {
        this.modificationTypeName = modificationTypeName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNewName() {
        return newName;
    }

    public void setNewName(String newName) {
        this.newName = newName;
    }

    public List<ParameterDiff> getParameterChanges() {
        return parameterChanges;
    }

    public void setParameterChanges(List<ParameterDiff> parameterChanges) {
        this.parameterChanges = parameterChanges;
    }
    
    public void addParameter(ParameterDiff parameter) {
        if(this.parameterChanges == null){
            this.parameterChanges = new LinkedList<ParameterDiff>();
        }
        this.parameterChanges.add(parameter);
    }
    
    public void printDiff() {
        if (this.getModificationTypeName().equals(OperationDiff.Modification.RENAME)) {
        	logger.log(Level.INFO, "Operation Rename from {0} to {1}.", new Object[]{this.getName(), this.getNewName()});
        }

        if (this.getModificationTypeName().equals(OperationDiff.Modification.NEW)) {
        	logger.log(Level.INFO, "Operation New {0}.", this.getName());
        }

        if (this.getModificationTypeName().equals(OperationDiff.Modification.ONLY_PARAMETER)) {
        	logger.log(Level.INFO, "Operation Modification Parameters {0}.", this.getName());
            for (ParameterDiff paramDiff : this.getParameterChanges()) {
                paramDiff.printDiff();
            }
        }
    }

}
